import { Metadata } from "next";
import { notFound } from "next/navigation";
import { createServerClient } from "~/trpc/server-client";
import { CourseDetail } from "~/components/courses/CourseDetail";
import type { CoursePageParams } from "~/types/route";

interface Props {
  params: CoursePageParams;
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const trpc = await createServerClient();
  const course = await trpc.courses.getById.fetch({ 
    courseId: params.courseId 
  });
  
  if (!course) {
    return {
      title: "课程不存在 - 在线教育平台",
    };
  }

  return {
    title: `${course.title} - 在线教育平台`,
    description: course.description || undefined,
  };
}

export default async function CoursePage({ params }: Props) {
  const trpc = await createServerClient();
  const course = await trpc.courses.getById.fetch({ 
    courseId: params.courseId 
  });

  if (!course) {
    notFound();
  }

  return (
    <div className="p-6">
      <CourseDetail course={course} />
    </div>
  );
} 